<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"  %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <title></title>
     <link href="../Styles/css.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">

        window.onerror = function () {
            return true;
        };
    </script>
    <script src="../Scripts/jquery.js" type="text/javascript"></script>
    <script src="../Styles/Math.uuid.js" type="text/javascript"></script>
    <script src="jquery-1.8.3.js"></script>
    <link href="../Styles/ts_css.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            var winHeight = $(document.body).outerHeight(true);
            $("#hidWinHeight").val(winHeight);
            //            alert($(window).height()); //浏览器当前窗口可视区域高度 
            //            alert($(document).height()); //浏览器当前窗口文档的高度 
            //            alert($(document.body).height()); //浏览器当前窗口文档body的高度 
            //            alert($(document.body).outerHeight(true)); //浏览器当前窗口文档body的总高度 包括border padding margin 

        });
    
    </script>
    <style type="text/css">
    
    a{
    text_decoration:none;
    }
    /* 列表样式2 * START --------------------*/
    table.tablist
    {
        width: 100%;
        font-size: 12px;
        margin: 0 auto;
        color: #515151;
        text-align: center;
        border-collapse: collapse; /*细线表格代码*/
    }
    table.tablist td
    {
        border: 1px solid #82AFE8; /*细线表格线条颜色*/
        height: 23px;
    }
    table.tablist tr.t1 td
    {
        background-color: #fff;
    }
    /* 交替行第一行的背景色 */
    table.tablist tr.t2 td
    {
        background-color: #EDEDED;
    }
    /* 交替行第二行的背景色 */
    table.tablist tr.t3 td
    {
        background-color: #BDDBFF;
    }
    /* 鼠标经过时的背景色 */
    table.tablist th
    {
        line-height: 23px;
        border: 1px solid #82AFE8;
        background: url(../images/table_dataList.gif) left center repeat-x;
        color: #005B7C;
    }
    table.tablist tbody tr td
    {
        text-align: center;
        white-space: nowrap;
    }
    
    
    /* 列表样式2 *END ---------------------*/
</style>
</head>
<body>
<div class="fjlb">
    <div class="fjlb_1">
       
        <div class="fjlb_1_jt" id="testtab">
            <a href="#" onclick="Effect('test',this.parentNode.id);">
                <img src="../images/jt1_t.png" id="imgJtd" alt="" /></a></div>
    </div>
    
  
       <input type="hidden" id="hang" value="${bean.roomCount}"> <br/>
       <input type="hidden" id="lie" value="${bean.floorCount }"><br/>
       <input type="hidden" id="name" value="${bean.projectId}"/><br/>
       <input type="hidden" id="build" value="${bean.buildName}"/><br/>
       
   <input type="button" value="生成房间" onclick="add()">
   <input type="button" value="提交" onclick="roomBase()" ><br/>    
   <div class="fjlb_2" id="divTj" style="overflow:scroll">
        <table class="tablist" id="tab" align="center" cellspacing="0">
           <tbody id="listHeader" style="background: #EFF3EF;">
                <tr id="daa">
                    <th rowspan="3">
                        楼层
                    </th>
                    <th>
                        单元       
                    </th>
                </tr>
                 <tr >

                    <th>
                       户数      
                    </th>
                  
                </tr>
            </tbody>
        </table>
  
        
    </div>
</div>
<script language="JavaScript" type="text/JavaScript">
 function system_category_add(title,url,w,h){
	layer_show(title,url,w,h);
}
 function system_category_room(title,url,w,h){
	layer_show(title,url,w,h);
}

 function system_category_upd(title,url,w,h){
	layer_show(title,url,w,h);
}  	
 function add(){
    var lie= $("#lie").val();
	   
    for(var j=0;j<lie;j++){	              
        var td = $("<td colspan='3'>"+(j+1)+"</td>");
                       
		td.appendTo($("#tab tbody tr:eq(0)"));		
	    }
	for(var i=0;i<lie*3;i++){
	    var td1 = $("<td>"+(i+1)+"</td>"); 
	    td1.appendTo($("#tab tbody tr:eq(1)"));
	}
	var hang=$("#hang").val();	
	var tra=$("<tr id=2></tr>");


	var tdb=$("<td>"+('户型')+"</td>");
	

	tdb.appendTo(tra);
	for(var k=0;k<lie*3;k++){
	var td=$("<td><select type='text' name='apart' id='apart' onchange='ajaxSelect(this.options[this.options.selectedIndex].text,"+(k+2)+")'><option value='两室两厅'>两室两厅</option><option value='三室一厅'>三室一厅</option><option value='三室两厅'>三室两厅</option></select></td>");
	td.appendTo(tra);
	}
	tra.appendTo($("#tab"));
	
	for(var i=0;i<hang;i++){
         var tr = $("<tr id="+(i+3)+"></tr>");
         var td = $("<td>"+(i+1)+"</td>");
         td.appendTo(tr);
         tr.appendTo($("#tab"));  
	}
	    for(var i=3;i<hang+3;i++){
    var tds= $("<td><select type='text' name='apart' id='apart' onchange='ajaxSelectrow(this.options[this.options.selectedIndex].text,"+(i)+")'><option value='两室两厅'>两室两厅</option><option value='三室一厅'>三室一厅</option><option value='三室两厅'>三室两厅</option></select></td>");     
        tds.appendTo($("#tab tbody tr:eq("+i+")"));
     }     
            
    for(var j=0;j<lie*3;j++){	
        for(var i=3;i<hang+3;i++){
    var td= $("<td><span>两室两厅</span><input type='checkbox' checked='true' name='resour'></td>");     
        td.appendTo($("#tab tbody tr:eq("+i+")"));
     }             
	    }
		    
}
   
   //整列$("#table1 tr td::nth-child(1)");   	
  function ajaxSelectrow(v,m){
      
      var str = "<span>"+v+"</span>"
     	var $datalen = $("#tab tr").eq(m).children('td');
        var te = "<input type='checkbox' checked='true' name='resour'>";
     	for(var i=2;i<$datalen.size();i++){    	    	    
     		if($datalen[i].lastChild.type=="checkbox"){    		
     		if($datalen[i].lastChild.checked==true){
     			$datalen.eq(i).html(str);
     	    	$datalen.eq(i).append($(te));	    	
     			  }
     		}else{
     			$datalen.eq(i).html(str);
     			
     		}
        	
     	}
    }	
    function ajaxSelect(v,n){
        var hang=$("#hang").val();
    	var str = "<span >"+v+"</span>"
    	var te = "<input type='checkbox' checked='true' name='resour'>";
    	
     	$("#tab tbody tr").each(function(){
  
          //var data=$(this).children('td').eq(n);
          for(var c=3;c<hang+3;c++){
          var data=$("#tab").find("tr").eq(c).children('td').eq(n);
          for(var i =0;i<data.length;i++){                  
        	  if(data[i].lastChild.type=="checkbox"){
        		  if(data[i].lastChild.checked==true){                    
        		  $(data).eq(i).html(str);//进行tr判断        		  
                  $(data).eq(i).append($(te));      
        		  }
        	  }       	
          }
         }                 
        });      
    } 
    

    
    
    function roomBase (){
	
		var name=$("#name").val();
		var build=$("#build").val();

		var trs = $("#tab tr");
		var arr=new Array();
		for (var i = 3; i < trs.length; i++) {
			var object="";  
			var data = trs.eq(i).children();
						
				for (var j = 2; j < data.length; j++) {
				    object=new Object;
					var huxing = $(data[j]).children('span').eq(0).text();
					object.apartmentLayoutId=huxing;//户型							
					object.unitId = Math.ceil((j-1)/3);//单元
					object.floor=i-2;//层数
					object.roomCode=i-2+"0"+((j-2)%3+1);//楼栋里一层的房间（房间号）
					object.projectId=name;
					object.buildId=build;
					object.roomId=Math.uuid();
					object.state=3;
					object.buildUpArea=110;
					object.innerArea=100;
					object.innerPrice=10000;
					object.unitPrice=9800;
					object.purposeId="销售";
					object.deleteState=1000000;//总价格无属性					
					arr.push(object);
				}					
		}
		
		 $.ajax({
			// url:"../qt/build/addRoomredis.do",
			 url:"../htbuild/addRoomredis.do",
			  type:"POST",
		      dataType: "json",
		      contentType:"application/json",
		      data:JSON.stringify(arr),
			 success:function(data){
			 
				 window.location.href='../htbuild/listhtroomredis.do';
			 }
		 });
			
   } 
    
  	
  	
  	

</script>
</body>
</html>


